﻿import QtQuick 2.15
import QtQuick.Controls 2.15


Item {
    width: screenWidth
    height: 180

    Item {
        id: backGround
        anchors.fill: parent
    }

    property string test

    property var m_diff

    property string m_showText

    property int m_contentWidth



    Rectangle{
        anchors.fill: backGround
        border.width: 1
        border.color: "#008af3"
        color: "#0764cd"
    }

    Rectangle{
        width: 850
        height: 150
        anchors.top: backGround.top
        anchors.topMargin: 15
        clip:true
        color: "transparent"

        Text{
            id:warningTest
            width : parent.width
            height : parent.height
            anchors.verticalCenter: parent.verticalCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 150
            font.bold: true
            color: "white"
            text:m_showText

            // SequentialAnimation on x{
            //     id:m_SequentialAnimation
            //     running: true
            //     loops:1         // 循环一次

            //     PropertyAnimation{
            //         id:m_PropertyAnimation
            //         from:0
            //         to: warningTest.contentWidth >= warningTest.width ? -(warningTest.contentWidth - warningTest.width): 0
            //         duration: 3000      // 持续5秒
            //     }

            //     onStopped: {
            //         m_PropertyAnimation.from = m_PropertyAnimation.to
            //         m_PropertyAnimation.to += - m_diff
            //         warningTest.text += ("    " + m_showText)
            //         m_SequentialAnimation.running = true

            //     }
            // }

            // Component.onCompleted:
            // {
            //     //组件初始化成功时，记录控件内容宽度与控件宽度的差值,以及原有的text内容
            //     m_diff = warningTest.width >= warningTest.contentWidth ? warningTest.width - warningTest.contentWidth : warningTest.contentWidth - warningTest.width
            //     m_showText = warningTest.text
            // }


            SequentialAnimation {
                id: sequentialAnimation
                loops: Animation.Infinite // 无限循环
                running: true

                // 从当前位置移动到 -width 的位置
                NumberAnimation {
                    id:teset
                    target: warningTest
                    properties: "x"
                    from: warningTest.width; to: -m_contentWidth
                    duration: 5000 // 持续时间5000毫秒
                    easing.type: Easing.Linear // 线性插值
                }

                // 瞬间跳回原点
                NumberAnimation {
                    target: warningTest
                    properties: "x"
                    to: 0
                    duration: 0 // 瞬间完成
                }
            }
        }
        // MouseArea{
        //     anchors.fill: parent

        //     onClicked: {
        //         m_showText += ("   " + "测试报警")
        //     }
        // }
    }




    Label{
        id:top_Date
        width: 200
        height: 40
        anchors.top: backGround.top
        anchors.topMargin: 10
        anchors.right: backGround.right
        anchors.rightMargin: 15
        font.pixelSize: 40
        color: "white"
    }

    Label{
        id:top_Time
        width: 200
        height: 40
        anchors.top: backGround.top
        anchors.topMargin: 60
        anchors.right: backGround.right
        font.pixelSize: 40
        color: "white"
    }

    Rectangle{
        width: 200
        height: 50
        anchors.top: backGround.top
        anchors.topMargin: 120
        anchors.right: backGround.right
        anchors.rightMargin: 10
        radius: 5
        color: "#66d8e9"
        border.width: 1
        border.color: "#81d5e9"

        Text{       // 界面显示标题显示框
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text:automaticPanel.visible ? "自动加工界面":
                singleReturnPanel.visible ? "单轴回待命点":
                manualPanel.visible ? "手动操作界面":
                formulaPanel.visible ? "配方设定界面" :
                ioPanel.visible ?     "输入输出界面" :
                warningMassagePanel.visible ? "报警信息界面" :
                warningCorePanel.visible ? "错误代码界面":
                parameterSettingPanel.visible ? "参数设置界面":
                commonSettingPanel.visible ? "常用参数设置":
                standbySettingPanel.visible ? "待命点设置界面":
                originSettingPanel.visible ? "原点设置界面" :
                limitSettingPanel.visible ? "限位设置界面":
                compensateSettingPanel.visible ? "补偿设置界面":
                zeroSettingPanel.visible ? "零点设置界面":
                                               test


        }
    }

    Timer{
        interval: 1000
        running: true
        repeat: true

        onTriggered: {
            top_Date.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
            top_Time.text = Qt.formatDateTime(new Date(), "hh:mm:ss")
        }
    }


    function signalChange(msgSignal)
    {
        console.log("msgSignal:" + msgSignal);

        if(msgSignal === m_showText)
        {
            return;
        }

        if("现在报警信号:" === msgSignal)
        {
            m_showText = msgSignal;
            warningTest.visible = false;
            sequentialAnimation.stop();
        }
        else
        {
            m_showText = msgSignal;
            warningTest.visible = true;
            m_contentWidth = warningTest.contentWidth
            sequentialAnimation.restart();
        }
    }



    Component.onCompleted: {
        top_Date.text = Qt.formatDateTime(new Date(), "yyyy-MM-dd")
        top_Time.text = Qt.formatDateTime(new Date(), "hh:mm:ss")

        Cpp_Connect.sig_WarningSignalChanged.connect(signalChange);
        sequentialAnimation.start();
    }
}
